//
//  UserViewController.m
//  Travel
//
//  Created by lanou3g on 15/12/7.
//  Copyright © 2015年 涂晓雨. All rights reserved.
//

#import "UserViewController.h"
#import "RegistViewController.h"
#import "loginViewController.h"
#import "UIImageView+WebCache.h"
@interface UserViewController ()<userName,UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)NSMutableArray *array;
@end

@implementation UserViewController


-(NSMutableArray *)array{

    if (_array == nil) {
        _array = [NSMutableArray array];
    }
    return _array;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height/3)];
//    view1.backgroundColor = [UIColor redColor];
    [self.view addSubview:view1];
    
    
    self.photo = [[UIImageView alloc]initWithFrame:CGRectMake((self.view.frame.size.width/2) - 50 , (view1.frame.size.height/2) - 64, 100, 100)];
    self.photo.layer.masksToBounds = YES;
    self.photo.layer.cornerRadius = 50;
    self.photo.backgroundColor = [UIColor whiteColor];
    [view1 addSubview:self.photo];
   self.button = [[UIButton alloc]initWithFrame:CGRectMake((self.view.frame.size.width/2) - 50 , (view1.frame.size.height/2) + 110 - 64, 100, 30)];
    [self.button setTitle:@"登陆" forState:UIControlStateNormal];
    [self.button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.button addTarget:self action:@selector(action) forControlEvents:UIControlEventTouchUpInside];
    [view1 addSubview:self.button];
    
    
    
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(view1.frame) , self.view.frame.size.width, self.view.frame.size.height - view1.frame.size.height)];
    [self.view addSubview:self.tableView];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    self.array = @[@"清除缓存",@"夜间模式",@"退出夜间模式"].mutableCopy;

}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return self.array.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1  reuseIdentifier:@"cell"];
    }
    cell.textLabel.text = self.array[indexPath.row];
    NSInteger size = [[SDImageCache sharedImageCache]getSize];
    if (indexPath.row == 0) {

         cell.detailTextLabel.text = [NSString stringWithFormat:@"%.2fMB",size/1024.0/1024.0];
    }
   
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.row == 0) {
        [[SDImageCache sharedImageCache]clearDisk];
        [self.tableView reloadData];
    }
    if (indexPath.row == 1) {
        self.view.window.backgroundColor = [UIColor blackColor];
        self.view.window.alpha = 0.5;
    }
    if (indexPath.row == 2) {
     
    self.view.window.alpha = 1;
    }

}
-(void)action{
    
    loginViewController *login = [[loginViewController alloc]init];
    login.delegate = self;
    [self presentViewController:login animated:YES completion:nil];

}

-(void)userName:(NSString *)name{
    self.photo.image = [UIImage imageNamed:@"6.jpg"];
    [self.button setTitle:name forState:UIControlStateNormal];
    
}
@end
